package com.example.leetdemo.finash;


public class Solution560 {


    // 暴力了。
    public int subarraySum(int[] nums, int k) {
        int[] dp = new int[nums.length];
        if (nums[0] == k) dp[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            int sum = 0;
            dp[i] = dp[i - 1];
            for (int j = i; j >= 0; j--) {
                sum += nums[j];
                if (sum == k) {
                    dp[i] = dp[i] + 1;
                }
                if (sum > k) {
                    break;
                }
            }
            dp[i] = Math.max(dp[i], dp[i - 1]);
        }
        return dp[nums.length - 1];
    }

    public static void main(String[] args) {
        Solution560 solution560 = new Solution560();
        System.err.println(solution560.subarraySum(new int[] {1,2,3}, 3));
    }
}
